﻿using System;
using System.Windows.Forms;
using Me.Amon.POS.V;
using Me.Amon.Properties;

namespace Me.Amon
{
    public partial class Main : Form
    {
        private IAuth _Auth;

        public Main()
        {
            InitializeComponent();

            this.Icon = Me.Amon.Properties.Resources.Icon;
        }

        private void Main_Load(object sender, EventArgs e)
        {
            //var setting = Settings.Default;
            //if (string.IsNullOrWhiteSpace(setting.Server))
            //{
            //    ShowSetup();
            //}

            ShowLogin();
        }

        public void ShowTips(Control control, string caption)
        {
            TtTips.SetToolTip(control, caption);
        }

        private UcLogin _Login;
        public void ShowLogin()
        {
            if (_Login == null)
            {
                _Login = new UcLogin();
                //_Login.Location = new System.Drawing.Point(9, 9);
                _Login.Init(this);
            }

            if (_Auth != null)
            {
                if (_Auth == _Login)
                {
                    return;
                }
                Controls.Remove(_Auth.Control);
            }

            Controls.Add(_Login);
            var size = _Login.Size;
            //size.Height += 18;
            //size.Width += 18;
            ClientSize = size;

            _Auth = _Login;
        }

        private UcSetup _Setup;
        public void ShowSetup()
        {
            if (_Setup == null)
            {
                _Setup = new UcSetup();
                _Setup.Location = new System.Drawing.Point(9, 9);
                _Setup.Init(this);
            }

            if (_Auth != null)
            {
                if (_Auth == _Setup)
                {
                    return;
                }
                Controls.Remove(_Auth.Control);
            }

            Controls.Add(_Setup);
            var size = _Setup.Size;
            size.Height += 18;
            size.Width += 18;
            ClientSize = size;

            _Auth = _Setup;
        }
    }
}
